package com.example.springboot.controller;

import com.example.springboot.domain.Admin;
import com.example.springboot.domain.Menu;
import com.example.springboot.dto.AdminDTO;
import com.example.springboot.dto.AdminDTO2;
import com.example.springboot.enums.ResCodeEnum;
import com.example.springboot.services.AdminService;
import com.example.springboot.services.MenuService;
import com.example.springboot.utils.ThreadLocalUtil;
import com.example.springboot.vo.ResVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/menu")
public class MenuController {

    @Autowired
    MenuService menuService;

    @GetMapping("/getMenu")
    public ResVO<List<Menu>> getMenu(HttpServletResponse response){

        Admin admin = ThreadLocalUtil.get();
        Integer roleId = admin.getRoleId();
        if(roleId == null){
            roleId = 2;
        }
        List<Menu> allMenus = menuService.getRoleMenus(roleId);
        //从redis取出对应角色的菜单数据
        return new  ResVO(ResCodeEnum.SELECTOK.getResCode(),"初始化成功", allMenus);
    }


}
